package com.hualan.sfzy.controller.counselor;

import com.hualan.sfzy.entity.counselor.CounselorPriceClassify;
import com.hualan.sfzy.service.counselor.CounselorPriceClassifyService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CounselorPriceClassifyController {
    @Autowired
    private CounselorPriceClassifyService counselorPriceClassifyService;

    @PostMapping("/counselorPriceClassify")
    public Result add(@RequestBody CounselorPriceClassify counselorPriceClassify){
        int num = counselorPriceClassifyService.add(counselorPriceClassify);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorPriceClassify/{id}")
    public Result remove(@PathVariable Integer id){
        int num = counselorPriceClassifyService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorPriceClassify")
    public Result removeBatch(Integer[] ids){
        int num = counselorPriceClassifyService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/counselorPriceClassify")
    public Result edit(@RequestBody CounselorPriceClassify counselorPriceClassify){
        int num = counselorPriceClassifyService.edit(counselorPriceClassify);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/counselorPriceClassify")
    public Result find(){
        List<CounselorPriceClassify> list = counselorPriceClassifyService.find();
        return Result.success(list);
    }

    @GetMapping("/counselorPriceClassify/{id}")
    public Result findById(@PathVariable Integer id){
        CounselorPriceClassify counselorPriceClassify = counselorPriceClassifyService.findById(id);
        return Result.success(counselorPriceClassify);
    }

    @GetMapping("/counselorPriceClassify/page")
    public Result findByPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                    CounselorPriceClassify counselorPriceClassify){
        Map<String, Object> map = counselorPriceClassifyService.findByPage(pageNum, pageSize, counselorPriceClassify);
        return Result.success(map);
    }
}
